﻿@model ThaireInvestmentWeb.Models.EditUnitTrustPurchaseModel
@{
    ViewBag.Title = "Edit UnitTrustPurchase";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {

        $("#TradeDate,#SettlementDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                yearRange: "-30:+40",
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")', // '../../Content/images/Calendar.png',
            });

        $("#CancelBtn").click(function (event) {
            //showConfirm("Are you sure to cancel ?", CancelBtnAction);
            showConfirm(null, CancelBtnAction);
            return false;
        });
        //$("#Unit").change(calAll);
        //$("#PriceUnit").change(calAll);
        //$("#ComRate").change(calAll);
        //$("#VatRate").change(calAll);
        //$("#WHTaxRate").change(calAll);
        $("#Unit").change(calAll);
        $("#PriceUnit").change(calAll);
        $("#ComRate").change(calAll);
        $("#VatRate").change(calAll);
        $("#WHTaxRate").change(calAll);
    });

        function CancelBtnAction(event) {
            window.location.href = 'EditUnitTrustHeader?headerId=@Model.HeaderID';
        }
        function calUnit() {

        }
        function calAll() {
            //alert('error xx');
            calGrossAmount();
            calComAmount();
            calVatAmount();
            calPurchaseValueNet();
            calWHTaxAmount();
            calNetSettle();
            //xxx($(this));
            //var xx = $(this).val();
            //$(this).val(FormatNumber2(parseDouble(xx)));
        }
        function calGrossAmount() {
            var v1 = $("#Unit").val();
            var v2 = $("#PriceUnit").val();
            if (v1 != '' && v2 != '') {
                var total = parseDouble(v1) * parseDouble(v2);
                $('#GrossAmount').val(FormatNumber2(total));
                //$("#Unit").val(FormatNumber2(parseDouble($("#Unit").val())));
                //$("#PriceUnit").val(FormatNumber2(parseDouble($("#PriceUnit").val())));
            }
        }
        function calComAmount() {
            var v1 = $("#ComRate").val();
            var v2 = $("#GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseDouble(v1) * parseDouble(v2) / 100;
                $('#ComAmount').val(FormatNumber2(total));
            }
        }
        function calPurchaseValueNet() {
            var v1 = $("#ComAmount").val();
            var v2 = $("#GrossAmount").val();
            var v3 = $("#VatAmount").val();
            if (v1 != '' && v2 != '' && v3 != '') {
                var total = parseDouble(v1) + parseDouble(v2) + parseDouble(v3);
                $('#PurchaseValueNet').val(FormatNumber2(total));
            }
        }
        function calNetSettle() {
            var v1 = $("#PurchaseValueNet").val();
            var v2 = $("#WHTaxAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseDouble(v1) - parseDouble(v2);
                $('#NetSettle').val(FormatNumber2(total));
            }
        }
        function calVatAmount() {
            var v1 = $("#VatRate").val();
            var v2 = $("#GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseDouble(v1) * parseDouble(v2) / 100;
                $('#VatAmount').val(FormatNumber2(total));
            }
        }
        function calWHTaxAmount() {
            var v1 = $("#WHTaxRate").val();
            var v2 = $("#GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseDouble(v1) * parseDouble(v2) / 100;
                $('#WHTaxAmount').val(FormatNumber2(total));
            }
        }

</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > <a href="@Url.Action("ManageUnitTrust", "UnitTrust", new { headerId = Model.Header.ID })">Unit Trust</a> > <a href="@Url.Action("EditUnitTrustHeader", "UnitTrust", new { headerId = Model.Header.ID })">Header</a> > Purchase
            </div>
        </td>
    </tr>
</table>
<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">INPUT 
            Purchase Unit Trust - Listed</td>
    </tr>
</table>

<table width="100%" border="0" align="center">
    <tr>
        <td>
            @Html.Partial("_UnitTrustHeaderView", Model.ScreenData.HeaderDTO)
            @Html.ValidationSummary(true)
            @using (Html.BeginForm("EditPurchaseTransaction", "UnitTrust", FormMethod.Post, new { id = "mainForm" }))
            {
                <table style="margin-top: 20px;" class="tableform" width="100%" border="5" align="center" cellspacing="2">
                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Transaction Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedTransactionType, Model.TransactionTypeList)
                            @Html.ValidationMessageFor(model => model.SelectedTransactionType)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Ref. No.<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.RefNo)
                            @Html.ValidationMessageFor(model => model.RefNo)</td>
                        <td>
                            <div align="right">Type of Payment<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedTypeOfPayment, Model.TypeOfPaymentList)
                            @Html.ValidationMessageFor(model => model.SelectedTypeOfPayment)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Trade Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.TradeDate, new { style = "width: 80px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.TradeDate) })
                            @Html.ValidationMessageFor(model => model.TradeDate) (Ex.31/12/2014)</td>
                        <td>
                            <div align="right">Settlement Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.SettlementDate, new { style = "width: 80px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.SettlementDate) })
                            @Html.ValidationMessageFor(model => model.SettlementDate) (Ex.31/12/2014)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Unit<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Unit, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Unit) })
                            @Html.ValidationMessageFor(model => model.Unit)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Price / Unit<span class="error"> * </span>:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.PriceUnit, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.PriceUnit) })
                            @Html.ValidationMessageFor(model => model.PriceUnit)</td>
                        <td>
                            <div align="right">Gross Amount<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.GrossAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.GrossAmount) })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">COM<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.ComRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.ComRate) })
                            @Html.ValidationMessageFor(model => model.ComRate) (%)</td>
                        <td>
                            <div align="right">COM AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.ComAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.ComAmount) })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">VAT Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.VatRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.VatRate) })
                            @Html.ValidationMessageFor(model => model.VatRate) (%)</td>
                        <td>
                            <div align="right">VAT AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.VatAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.VatAmount) })</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Purchase Value (Net)<span class="error"></span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.PurchaseValueNet, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.PurchaseValueNet) })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">W/H TAX Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.WHTaxRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.WHTaxRate) })
                            @Html.ValidationMessageFor(model => model.WHTaxRate)
                            &nbsp;(%)</td>
                        <td>
                            <div align="right">W/H TAX AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.WHTaxAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.WHTaxAmount) })
                        </td>

                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Net Settle AMT. incl W/T<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.NetSettle, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.NetSettle) })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Physical<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedPhysical, Model.PhysicalList)  @Html.ValidationMessageFor(model => model.SelectedPhysical)</td>
                        <td>
                            <div align="right">Keep at<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedKeepAt, Model.KeepAtList)  @Html.ValidationMessageFor(model => model.SelectedKeepAt)</td>
                    </tr>
                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                </table>
    
                <table width="95%" height="85" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">

                                <input id="SubmitBtn" type="submit" name="SubmitBtn" value=" Submit " class="button" need-confirm="true" />
                                &nbsp;&nbsp; 
                            <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button" />
                            </div>
                        </td>
                    </tr>

                </table>
    
                @Html.HiddenFor(x => x.UpdateMode);
                @Html.HiddenFor(x => x.HeaderID);
                @Html.HiddenFor(x => x.TransactionID);

            }

        </td>
    </tr>
</table>
